/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.emocbc.dbmapping.persistence;

import com.elcom.emocbc.util.IntegerResultSetHandler;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.MessageFormat;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

/**
 *
 * @author GiangLT
 */
public class SequencePersistance {

    public int getNextSequence(String sequenceName) throws SQLException {
        ResultSetHandler<Integer> resultSetHandler = new IntegerResultSetHandler();
        Connection con = DbAccess.getInstance().getConnection();
        QueryRunner qr = new QueryRunner();
        String sql = MessageFormat.format("SELECT {0}.NEXTVAL from dual", sequenceName);
        try {
            return qr.query(con, sql, resultSetHandler);
        } finally {
            DbUtils.closeQuietly(con);
        }
    }
}
